package project.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import project.DAO.materialDAO;
import project.DO.materialDo;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
public class materialController {
    @Autowired
    materialDAO materialDao;

    @RequestMapping("/material")
    public String material(HttpServletRequest request) {
        String name = request.getParameter("name");
        String number = request.getParameter("number");
        if (name != null) {
            materialDao.insertMaterial(name, number);
        }
        return "materials";
    }
    @RequestMapping("/material1")
    public String material1(HttpServletRequest request, Map map)
    {
        String name = request.getParameter("materialName");
        List<materialDo> materialDoList;
        if(name!=null)
        {
            materialDoList=materialDao.selectMaterial(name);
            map.put("materials",materialDoList);
        }
        return "materials";
    }
    @RequestMapping("/material3")
    public String material3(Map map)
    {
        List<materialDo> materialDoList;
        materialDoList=materialDao.selectAll();
        map.put("materials",materialDoList);
        return "materials";
    }
}
